Skip to content

feat: improve triples matching performance#534

Merged
samuel-bustamante merged 1 commit intorudof-project:masterfrom
bishoyroufael:feat/improve-triples-matching-performance
Mar 12, 2026
Merged

feat: improve triples matching performance#534
samuel-bustamante merged 1 commit intorudof-project:masterfrom
bishoyroufael:feat/improve-triples-matching-performance

Conversation

@bishoyroufael
Copy link

@bishoyroufael bishoyroufael commented Mar 11, 2026

Hi,

The current triples matching algorithm was an overkill since it needs to retrieve all the triples always. I have improved that by utilizing the correct index function based on what's available. The performance gains are almost 1000x for large graphs in cases like SHACL validation.

Summary:

File changed: rudof_rdf/src/rdf_impl/in_memory_graph.rs

The new triples_matching dispatches to the best oxrdf::Graph index based
on which of the three positions carry a concrete value vs a wildcard (Any):

Pattern Index used Complexity
(S, P, O) graph.contains(triple_ref) O(1)
(S, P, ?) graph.objects_for_subject_predicate(s, p) O(k) — SPO
(S, ?, ?) graph.triples_for_subject(s) O(k) — SPO
(?, P, ?) graph.triples_for_predicate(p) O(k) — POS
(?, P, O) graph.subjects_for_predicate_object(p, o) O(k) — POS
(?, ?, O) graph.triples_for_object(o) O(k) — OSP
(S, ?, O) triples_for_subject(s) + filter by O O(k_s)
(?, ?, ?) graph.iter() O(n) — unavoidable

@bishoyroufael bishoyroufael force-pushed the feat/improve-triples-matching-performance branch from 9a960ed to fe2c64d Compare March 11, 2026 14:02
@bishoyroufael bishoyroufael force-pushed the feat/improve-triples-matching-performance branch from fe2c64d to a1297db Compare March 11, 2026 14:22
@samuel-bustamante samuel-bustamante self-assigned this Mar 12, 2026
@samuel-bustamante samuel-bustamante added the rdf Related to RDF support label Mar 12, 2026
@samuel-bustamante
Copy link
Collaborator

Great optimization, thanks!

@samuel-bustamante samuel-bustamante merged commit d9b1910 into rudof-project:master Mar 12, 2026
10 checks passed
@bishoyroufael bishoyroufael deleted the feat/improve-triples-matching-performance branch March 12, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rdf Related to RDF support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants